
export class Signal<T = any> {

    private listeners: Set<(event: T) => void>;

    public active: boolean = true;

    constructor() {
        this.listeners = new Set();
    }

    add(listener: (event: T) => void): void {
        this.listeners.add(listener);
    }

    remove(listener: (event: T) => void): void {
        this.listeners.delete(listener);
    }

    dispatch(event?: T): void {
        if (!this.active) return;
        this.listeners.forEach(fn => {
            fn(event);
        });
    }

}